const express = require('express');

const cookieParser = require('cookie-parser');

const app = express();

// 调用cookieParser中间件
app.use(cookieParser());

// 设置cookie
app.get('/set-cookie',(req,res)=>{

    // 设置cookie
    // 参数1:cookie的name
    // 参数2：cookie的value
    //参数3：配置
        // maxAge:1000*10 10秒过期
    res.cookie("username","xiaoli",{
        maxAge:1000*60*60
    });

    res.send('成功');
})


//获取cookie
app.get('/get-cookie',(req,res)=>{

    console.log(req.cookies);

    res.send('获取成功'+req.cookies.username);
})


//删除cookie
app.get('/del-cookie',(req,res)=>{

    res.clearCookie('username')

    res.send('删除cookie');
});


app.listen(80,()=>{
    console.log("启动成功");
})